home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <string.h>
-
- #include "DeskLib:WimpSWIs.h"
-
- #include "Shell.Array.h"
- #include "Shell.Extra.h"
- #include "Shell.SafeAlloc.h"
-
-
- #define COLUMN_WIDTH 10
-
-
- typedef struct {
- double **data;
- wimp_point size;
- }
- Shell_2DDoubleArrayInfo;
-
-
-
-
-
- static void Shell_2DDoubleArrayRedrawer(
- Shell_convertpoint convert,
- wimp_point rectsize,
- void *reference,
- const wimp_rect *redrawrect
- )
- {
- wimp_rect rect = *redrawrect;
- Shell_2DDoubleArrayInfo *info = (Shell_2DDoubleArrayInfo *) reference;
- int i, j;
- char s[64];
-
- Shell_ConvertToSubTextRect2( &rect, rectsize);
- rect.min.x /= COLUMN_WIDTH;
- rect.max.x /= COLUMN_WIDTH;
-
-
- for ( i=rect.min.x; i<=rect.max.x; i++) {
- int x = i*COLUMN_WIDTH*Shell_TEXTXSIZE;
-
- for ( j=rect.min.y; j<=rect.max.y; j++) {
-
- sprintf( s, "%.2g", info->data[j][i]);
- /* Note the order. This is so that matrices are displayed with first */
- /* indice denoting the row, and the second denoting the column. */
- s[ COLUMN_WIDTH-1] = '\0';
-
- Shell_PrintString( s, x, rectsize.y - j*Shell_TEXTYSIZE, convert);
-
- }
- }
-
- return;
- }
-
-
-
-
-
- static BOOL Shell_2DDoubleArraySaver( char *filename, Shell_rectblock *r)
- {
- FILE *f;
- Shell_2DDoubleArrayInfo *info = (Shell_2DDoubleArrayInfo *) r->reference;
- int x, y;
-
- f = fopen( filename, "w");
- if (!f) return FALSE;
-
- for ( y=0; y<info->size.y; y++) {
- for ( x=0; x<info->size.x; x++) {
- fprintf( f, "%.2g", info->data[y][x]);
- fprintf( f, "\t");
- }
- fprintf( f, "\n");
- }
-
- fclose( f);
-
- return TRUE;
- }
-
-
-
-
-
- Shell_rectblock *Shell_Add2DDoubleArray(
- Shell_windblock *windblock,
- int x, int y,
- int xsize, int ysize,
- int forecol, int backcol,
- double **data
- )
-
- { Shell_rectblock *r;
- Shell_2DDoubleArrayInfo *info =
- Shell_SafeMalloc( sizeof( Shell_2DDoubleArrayInfo));
-
-
- info->data = data;
- info->size.x = xsize;
- info->size.y = ysize;
-
- r = Shell_AddRectangle2(
- windblock,
- x, y - ysize*Shell_TEXTYSIZE,
- x + xsize * COLUMN_WIDTH * Shell_TEXTXSIZE, y,
- Shell_2DDoubleArrayRedrawer,
- (void *) info
- );
-
- r->saver = Shell_2DDoubleArraySaver;
- r->size = COLUMN_WIDTH * xsize * ysize;
-
- Shell_MakeRectIcon( r, forecol, backcol, "r1");
-
- return r;
- }
-
-
-